<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('课程分配学生')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
				    <input type="hidden" id="courseId" name="courseId" th:value="${courseChoose.courseId}">
					<div class="select-list">
						<ul>
							<li>
								<label>学号：</label>
								<input type="text" name="no"/>
							</li>
							<li>
								<label>姓名：</label>
								<input type="text" name="name"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="selectStudent()" shiro:hasPermission="system:choose:assignStudents:add">
	                <i class="fa fa-plus"></i> 添加学生
	            </a>
				<a class="btn btn-danger multiple disabled" onclick="cancelAuthUserAll()" shiro:hasPermission="system:choose:assignStudents:removeAll">
					<i class="fa fa-remove"></i> 批量删除
				</a>
		        <a class="btn btn-warning" onclick="closeItem()">
		            <i class="fa fa-reply-all"></i> 关闭
		        </a>
	        </div>

	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var removeFlag = [[${@permission.hasPermi('system:choose:assignStudents:remove')}]];
		var gradeIdDatas = [[${@dict.getType('sys_grade')}]];
		var professionalIdDatas = [[${@dict.getType('sys_professional')}]];
		var classIdDatas = [[${@dict.getType('sys_class')}]];
		var prefix = ctx + "system/choose";

		$(function() {
			var options = {
		        url: prefix + "/assignStudents/list",
				createUrl: prefix + "/add",
				updateUrl: prefix + "/edit/{id}",
				removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				modalName: "学生信息",
		        columns: [{
		            checkbox: true
		        },
				{
					field: 'id',
					title: '主键',
					visible: false
				},
				{
					field: 'no',
					title: '学号'
				},
				{
					field: 'name',
					title: '姓名'
				},
				{
					field: 'gradeId',
					title: '年级',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(gradeIdDatas, value);
					}
				},
				{
					field: 'professionalId',
					title: '专业',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(professionalIdDatas, value);
					}
				},
				{
					field: 'classId',
					title: '班级',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(classIdDatas, value);
					}
				},
				{
					field: 'tel',
					title: '电话'
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cancelAuthUser(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		function queryParams(params) {
			var search = $.table.queryParams(params);
			search.roleId = $("#roleId").val();
			return search;
		}

		/* 分配学生-选择学生 */
		function selectStudent() {
			var url = prefix + '/assignStudents/selectStudents/' + $("#courseId").val();
		    $.modal.open("选择学生", url,1100,680);
		}

		/* 分配学生-批量删除 */
		function cancelAuthUserAll(userId) {
		    var rows = $.table.selectFirstColumns();
       		if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
       		$.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
    			var data = { "courseId": $("#courseId").val(), "sIds": rows.join() };
    			$.operate.submit(prefix + "/assignStudents/removeAll", "post", "json", data);
    		});
		}

		/* 分配学生-删除 */
		function cancelAuthUser(sId) {
			$.modal.confirm("确认要删除该条数据吗？", function() {
				$.operate.post(prefix + "/assignStudents/remove", { "courseId": $("#courseId").val(), "sId": sId });
		    })
		}
	</script>
</body>
</html>
